package com.dnjn.happiness.emo.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dnjn.happiness.common.cloud.controller.BaseController;
import com.dnjn.happiness.common.core.domain.R;
import com.dnjn.happiness.common.core.utils.bean.BeanUtils;
import com.dnjn.happiness.common.core.web.domain.AjaxResult;
import com.dnjn.happiness.common.log.annotation.Log;
import com.dnjn.happiness.common.log.enums.BusinessType;
import com.dnjn.happiness.common.security.annotation.InnerAuth;
import com.dnjn.happiness.common.security.utils.SecurityUtils;
import com.dnjn.happiness.emo.api.domain.UserHcmQxPtdata;
import com.dnjn.happiness.emo.domain.vo.UserHcmQxPtdataVO;
import com.dnjn.happiness.emo.service.IUserHcmQxPtdataService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

/**
 * 考勤记录userHcmQxPtdataController
 *
 * @author amber
 * @date 2024-03-13
 */
@Tag(name = "emo userHcmQxPtdata 考勤记录userHcmQxPtdata", description = "考勤记录userHcmQxPtdata")
@RestController
@RequestMapping("/userHcmQxPtdata")
public class UserHcmQxPtdataController extends BaseController {
    @Autowired
    private IUserHcmQxPtdataService userHcmQxPtdataService;

    @InnerAuth
    @GetMapping("/selectAttendance/{userId}/{time}")
    public R<List<UserHcmQxPtdata>> selectAttendance(@PathVariable Long userId,@PathVariable String time){
        return R.ok(userHcmQxPtdataService.selectAttendance(userId,time));
    }

    /**
     * 查询考勤记录userHcmQxPtdata列表
     */
    //@RequiresPermissions("@ss.hasPermi('emo:userHcmQxPtdata:list')")
    @PostMapping("/list")
    @Log(title = "emo", businessType = BusinessType.LIST)
    public AjaxResult list(@RequestBody UserHcmQxPtdataVO vo, @RequestParam(defaultValue = "1") Integer current, @RequestParam(defaultValue = "10") Integer size) {
        UserHcmQxPtdata userHcmQxPtdata = new UserHcmQxPtdata();
        BeanUtils.copyPropsIgnoreNull(vo, userHcmQxPtdata);
        Page page = Page.of(current, size);
        Page<UserHcmQxPtdata> list = userHcmQxPtdataService.page(page, Wrappers.query(userHcmQxPtdata));
        return success(list);
    }

    /**
     * 获取考勤记录userHcmQxPtdata详细信息
     */
    //@RequiresPermissions("@ss.hasPermi('emo:userHcmQxPtdata:query')")
    @GetMapping(value = "/{id}")
    @Log(title = "biz", businessType = BusinessType.SELECT)
    public AjaxResult get(@PathVariable("id") Long id) {
        return success(userHcmQxPtdataService.getById(id));
    }

    /**
     * 新增考勤记录userHcmQxPtdata
     */
    @Log(title = "考勤记录userHcmQxPtdata", businessType = BusinessType.INSERT)
    //@RequiresPermissions("@ss.hasPermi('emo:userHcmQxPtdata:add')")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody UserHcmQxPtdataVO vo) {
        UserHcmQxPtdata userHcmQxPtdata = new UserHcmQxPtdata();
        BeanUtils.copyPropsIgnoreNull(vo, userHcmQxPtdata);

        userHcmQxPtdata.setCreateBy(SecurityUtils.getUsername());
        return toAjax(userHcmQxPtdataService.save(userHcmQxPtdata));
    }

    /**
     * 修改考勤记录userHcmQxPtdata
     */
    @Log(title = "考勤记录userHcmQxPtdata", businessType = BusinessType.UPDATE)
    //@RequiresPermissions("@ss.hasPermi('emo:userHcmQxPtdata:edit')")
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody UserHcmQxPtdataVO vo) {
        UserHcmQxPtdata userHcmQxPtdata = new UserHcmQxPtdata();
        BeanUtils.copyPropsIgnoreNull(vo, userHcmQxPtdata);
        return toAjax(userHcmQxPtdataService.updateById(userHcmQxPtdata));
    }

    /**
     * 删除考勤记录userHcmQxPtdata
     */
    @Log(title = "考勤记录userHcmQxPtdata", businessType = BusinessType.DELETE)
    //@RequiresPermissions("@ss.hasPermi('emo:userHcmQxPtdata:remove')")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(userHcmQxPtdataService.removeBatchByIds(Arrays.asList(ids)));
    }

    /**
     * 手动获取昨日考勤数据
     */
    //@RequiresPermissions("@ss.hasPermi('emo:userHcmQxPtdata:query')")
    @GetMapping(value = "/getYesterdayUserHcmQxPtdataRecord")
    @Log(title = "biz", businessType = BusinessType.SELECT)
    public AjaxResult getYesterdayUserHcmQxPtdataRecord() {
        userHcmQxPtdataService.getYesterdayUserHcmQxPtdataRecord();
        return success();
    }

}
